home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / gnu / a2_0b_Emacs_sr.lha / Emacs-19.25 / lisp / lpr.el < prev    next >
Lisp/Scheme  |  1994-05-03  |  5KB  |  143 lines

  1. ;;; lpr.el --- print Emacs buffer on line printer.
  2.  
  3. ;; Copyright (C) 1985, 1988, 1992, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: unix
  7.  
  8. ;; This file is part of GNU Emacs.
  9.  
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  22. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ;;; Commentary:
  25.  
  26. ;; Commands to send the region or a buffer your printer.  Entry points
  27. ;; are `lpr-buffer', `print-buffer', lpr-region', or `print-region'; option
  28. ;; variables include `lpr-switches' and `lpr-command'.
  29.  
  30. ;;; Code:
  31.  
  32. ;;;###autoload
  33. (defvar lpr-switches nil 
  34.   "*List of strings to pass as extra switch args to `lpr' when it is invoked.")
  35.  
  36. (defvar lpr-add-options (eq system-type 'berkeley-unix)
  37.   "*Non-nil means construct -T and -J options for the `lpr'.")
  38.  
  39. ;;;###autoload
  40. (defvar lpr-command
  41.   (if (memq system-type '(usg-unix-v dgux hpux irix))
  42.       "lp" "lpr")
  43.   "*Shell command for printing a file")
  44.  
  45. (defvar lpr-headers-switches
  46.   (if (memq system-type '(usg-unix-v hpux)) nil "-p")
  47.   "*List of strings to use as options for `lpr' to request page headings.")
  48.  
  49. (defvar print-region-function nil
  50.   "Function to call to print the region on a printer.
  51. See definition of `print-region-1' for calling conventions.")
  52.  
  53. ;;;###autoload
  54. (defun lpr-buffer ()
  55.   "Print buffer contents as with Unix command `lpr'.
  56. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  57.   (interactive)
  58.   (print-region-1 (point-min) (point-max) lpr-switches nil))
  59.  
  60. ;;;###autoload
  61. (defun print-buffer ()
  62.   "Print buffer contents as with Unix command `lpr -p'.
  63. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  64.   (interactive)
  65.   (print-region-1 (point-min) (point-max) lpr-switches t))
  66.  
  67. ;;;###autoload
  68. (defun lpr-region (start end)
  69.   "Print region contents as with Unix command `lpr'.
  70. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  71.   (interactive "r")
  72.   (print-region-1 start end lpr-switches nil))
  73.  
  74. ;;;###autoload
  75. (defun print-region (start end)
  76.   "Print region contents as with Unix command `lpr -p'.
  77. `lpr-switches' is a list of extra switches (strings) to pass to lpr."
  78.   (interactive "r")
  79.   (print-region-1 start end lpr-switches t))
  80.  
  81. (defun print-region-1 (start end switches page-headers)
  82.   (let ((name (concat (buffer-name) " Emacs buffer"))
  83.     (width tab-width))
  84.     (save-excursion
  85.       (message "Spooling...")
  86.       (if (/= tab-width 8)
  87.       (progn
  88.         (print-region-new-buffer start end)
  89.         (setq tab-width width)
  90.         (save-excursion
  91.           (goto-char end)
  92.           (setq end (point-marker)))
  93.         (untabify (point-min) (point-max))))
  94.       (if page-headers
  95.       (if lpr-headers-switches
  96.           ;; On BSD, use an option to get page headers.
  97.           (setq switches (append (if (stringp lpr-headers-switches)
  98.                      (list lpr-headers-switches)
  99.                         lpr-headers-switches)
  100.                      switches))
  101.         (print-region-new-buffer start end)
  102.         (call-process-region start end "pr" t t nil)
  103.         (setq start (point-min) end (point-max))))
  104.       (apply (or print-region-function 'call-process-region)
  105.          (nconc (list start end lpr-command
  106.               nil nil nil)
  107.             (nconc (and lpr-add-options
  108.                 (list "-J" name "-T" name))
  109.                switches)))
  110.       (if (markerp end)
  111.       (set-marker end nil))
  112.       (message "Spooling...done"))))
  113.  
  114. ;; This function copies the text between start and end
  115. ;; into a new buffer, makes that buffer current,
  116. ;; and sets start and end to the buffer bounds.
  117. ;; start and end are used free.
  118. (defun print-region-new-buffer (ostart oend)
  119.   (or (string= (buffer-name) " *spool temp*")
  120.       (let ((oldbuf (current-buffer)))
  121.     (set-buffer (get-buffer-create " *spool temp*"))
  122.     (widen) (erase-buffer)
  123.     (insert-buffer-substring oldbuf ostart oend)
  124.     (setq start (point-min) end (point-max)))))
  125.  
  126. (defun printify-region (begin end)
  127.   "Turn nonprinting characters (other than TAB, LF, SPC, RET, and FF)
  128. in the current buffer into printable representations as control or
  129. hexadecimal escapes."
  130.   (interactive "r")
  131.   (save-excursion
  132.     (goto-char begin)
  133.     (let (c)
  134.       (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t)
  135.     (setq c (preceding-char))
  136.     (delete-backward-char 1)
  137.     (insert 
  138.      (if (< c ?\ )
  139.          (format "\\^%c" (+ c ?@))
  140.        (format "\\%02x" c)))))))
  141.  
  142. ;;; lpr.el ends here
  143.